home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / FindDialog.java < prev    next >
Text File  |  1998-11-02  |  5KB  |  187 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class FindDialog extends Dialog {
  8.     
  9.     public FindDialog(Frame parent, boolean modal)
  10.     {
  11.         super(parent, modal);
  12.  
  13.         // This code is automatically generated by Visual Cafe when you add
  14.         // components to the visual environment. It instantiates and initializes
  15.         // the components. To modify the code, only use code syntax that matches
  16.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  17.         // parse your Java file into its visual environment.
  18.         //{{INIT_CONTROLS
  19.         setLayout(null);
  20.         setBackground(java.awt.Color.lightGray);
  21.         setSize(294,86);
  22.         setVisible(false);
  23.         m_findlabel.setText("Find What");
  24.         add(m_findlabel);
  25.         m_findlabel.setBounds(5,6,80,16);
  26.         add(m_findText);
  27.         m_findText.setBounds(5,30,190,20);
  28.         m_findButton.setLabel("Find");
  29.         add(m_findButton);
  30.         m_findButton.setBounds(209,6,70,20);
  31.         m_cancelButton.setLabel("Cancel");
  32.         add(m_cancelButton);
  33.         m_cancelButton.setFont(new Font("Dialog", Font.PLAIN, 12));
  34.         m_cancelButton.setBounds(209,30,70,20);
  35.         add(m_statuslabel);
  36.         m_statuslabel.setBounds(161,54,120,24);
  37.         m_statuslabel.setVisible(false);
  38.         m_matchCase.setLabel("Match case");
  39.         add(m_matchCase);
  40.         m_matchCase.setBackground(java.awt.Color.lightGray);
  41.         m_matchCase.setBounds(5,54,84,20);
  42.         setTitle("Dialog2");
  43.         //}}
  44.  
  45.         //{{REGISTER_LISTENERS
  46.         SymWindow aSymWindow = new SymWindow();
  47.         this.addWindowListener(aSymWindow);
  48.         SymAction lSymAction = new SymAction();
  49.         m_findButton.addActionListener(lSymAction);
  50.         m_cancelButton.addActionListener(lSymAction);
  51.         //}}
  52.     }
  53.     
  54.     public void addNotify()
  55.     {
  56.         // Record the size of the window prior to calling parents addNotify.
  57.         Dimension d = getSize();
  58.         
  59.         super.addNotify();
  60.  
  61.         if (fComponentsAdjusted)
  62.             return;
  63.  
  64.         // Adjust components according to the insets
  65.         Insets insets = getInsets();
  66.         setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
  67.         Component components[] = getComponents();
  68.         for (int i = 0; i < components.length; i++)
  69.         {
  70.             Point p = components[i].getLocation();
  71.             p.translate(insets.left, insets.top);
  72.             components[i].setLocation(p);
  73.         }
  74.         fComponentsAdjusted = true;
  75.     }
  76.  
  77.  
  78.     // Used for addNotify check.
  79.     boolean fComponentsAdjusted = false;
  80.  
  81.  
  82.     public FindDialog(Frame parent, String title, boolean modal, FindReplace fr)
  83.     {
  84.         this(parent, modal);
  85.         setTitle(title);
  86.         m_find = fr;
  87.         m_findText.setText(m_find.getFind());
  88.         m_matchCase.setState(m_find.isCase());
  89.     }
  90.  
  91.  
  92.  
  93.     //{{DECLARE_CONTROLS
  94.     java.awt.Label m_findlabel = new java.awt.Label();
  95.     java.awt.TextField m_findText = new java.awt.TextField();
  96.     java.awt.Button m_findButton = new java.awt.Button();
  97.     java.awt.Button m_cancelButton = new java.awt.Button();
  98.     java.awt.Label m_statuslabel = new java.awt.Label();
  99.     java.awt.Checkbox m_matchCase = new java.awt.Checkbox();
  100.     //}}
  101.     FindReplace m_find;
  102.  
  103.     private void find()
  104.     {
  105.         FindReplaceEngine fre;
  106.         m_find.setFind(m_findText.getText().trim());
  107.         m_find.setCase(m_matchCase.getState());
  108.         fre = new FindReplaceEngine(m_find);
  109.         fre.FindIt();
  110.         if(m_find.isFoundIt()) m_statuslabel.setText("Found " + m_find.getOccur());
  111.         else {
  112.             m_statuslabel.setText("End of File");
  113.             this.getToolkit().beep();
  114.         }
  115.         m_statuslabel.setVisible(true);
  116.     }
  117.  
  118.  
  119.  
  120.     class SymWindow extends java.awt.event.WindowAdapter
  121.     {
  122.         public void windowClosing(java.awt.event.WindowEvent event)
  123.         {
  124.             Object object = event.getSource();
  125.             if (object == FindDialog.this)
  126.                 FindDialog_WindowClosing(event);
  127.         }
  128.     }
  129.  
  130.     void FindDialog_WindowClosing(java.awt.event.WindowEvent event)
  131.     {
  132.         // to do: code goes here.
  133.              
  134.         FindDialog_WindowClosing_Interaction1(event);
  135.     }
  136.  
  137.     void FindDialog_WindowClosing_Interaction1(java.awt.event.WindowEvent event)
  138.     {
  139.         try {
  140.             this.dispose();
  141.         } catch (Exception e) {
  142.         }
  143.     }
  144.  
  145.     class SymAction implements java.awt.event.ActionListener
  146.     {
  147.         public void actionPerformed(java.awt.event.ActionEvent event)
  148.         {
  149.             Object object = event.getSource();
  150.             if (object == m_findButton)
  151.                 mFindButton_ActionPerformed(event);
  152.             else if (object == m_cancelButton)
  153.                 mCancelButton_ActionPerformed(event);
  154.         }
  155.     }
  156.  
  157.     void mFindButton_ActionPerformed(java.awt.event.ActionEvent event)
  158.     {
  159.         // to do: code goes here.
  160.              
  161.         m_findButton_ActionPerformed_Interaction1(event);
  162.     }
  163.  
  164.     void m_findButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  165.     {
  166.         try {
  167.             this.find();
  168.         } catch (Exception e) {
  169.         }
  170.     }
  171.  
  172.     void mCancelButton_ActionPerformed(java.awt.event.ActionEvent event)
  173.     {
  174.         // to do: code goes here.
  175.              
  176.         m_cancelButton_ActionPerformed_Interaction1(event);
  177.     }
  178.  
  179.     void m_cancelButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  180.     {
  181.         try {
  182.             this.dispose();
  183.         } catch (Exception e) {
  184.         }
  185.     }
  186. }
  187.